package likong.bibliothek.pages.spender;

import likong.bibliothek.obj.Autor;
import likong.bibliothek.obj.Spender;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;


import Persondata.Person;

public abstract class SpenderFormPanel extends Panel {
	private static final long serialVersionUID = 1L;
	public SpenderFormPanel(String id, IModel<Spender> model, final String buttonLabel) {
		super(id, model);
		
		SpenderForm spenderForm = new SpenderForm("form", model);
		spenderForm.add(new TextField<String>("name").setRequired(true));
		spenderForm.add(new TextField<String>("strasse"));
		spenderForm.add(new TextField<Integer>("nummer"));
		spenderForm.add(new TextField<String>("stadt"));
		spenderForm.add(new TextField<Integer>("plz"));
		spenderForm.add(new FeedbackPanel("feedback"));
		spenderForm.add(new Button("buttonLabel", new Model<String>(buttonLabel)));
		add(spenderForm);
		
	}
	
	protected abstract void onSubmitModelHandle(final IModel<Spender> model);
	
	private class SpenderForm extends Form<Spender> {
		private static final long serialVersionUID = 1L;

		public SpenderForm(String id, IModel<Spender> model) {
			super(id, model);
		}

		protected void onSubmit() {
			// *Wie* gespeichert wird, wird hier nicht definiert! Dazu muss die abstrakte äußere Klasse definiert werden. 
			onSubmitModelHandle(getModel());
		}
	}
}
